package 力扣日常刷题.木22二月.第11天217;

/**
 * @author 帅小伙
 * @date 2022/2/17
 * @description
 */
public class Demo72JZ二进制中1的个数 {

    public int hammingWeight(int n) {
        int ans = 0;
        while (n != 0) {
            n &= n - 1;
            ans++;
        }
        return ans;
    }
}
